var app = getApp()
var Utils = require('../../../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    back_orser: 0,
    textareatxt: "",
    popif: false,
    inquiry: "",
    argeen: true,
    steps: ["医生开方", "选择药品", "医生医嘱", '发送处方'],
    upload_picture_list: [],
    stepnum: 0,
    speedlist: [{
        tit: "祛斑/去痘印",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "痔疮/痘痘",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "去黑头",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "脚气",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "阳痿",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "早泄",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "湿疹",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "避孕",
        text: "的哈哈大华大厦宏大的"
      },
      {
        tit: "阴道炎",
        text: "的哈哈大华大厦宏大的"
      },
    ]
  },
  //调单提交
  infomationbtn(e) {
    var that = this
    let vals = e.detail.value;
    var ifzj = that.data.ifzj
    var zhenduan = e.detail.value.zhenduan
    var yongyao = e.detail.value.yongyao
    var text = e.detail.target.dataset.text
    var c_id = that.data.id
    var j_id = that.data.j_id
    var key_words = that.data.key_words
    var back_orser = that.data.back_orser
    var zid = that.data.zid
    if (zhenduan == '') {
      wx.showToast({
        title: '请输入诊断结果',
        icon: 'none'
      })
    } else if (yongyao == '') {
      wx.showToast({
        title: '请输入建议用药',
        icon: 'none'
      })
    } else {
      // wx.navigateTo({
      //   url: '/hyb_yl/backstageServices/pages/xuanzeyaopin/xuanzeyaopin?inquiry=' + this.data.inquiry + '&zhenduan=' + zhenduan + '&yongyao=' + yongyao + '&text=' + text + '&c_id=' + c_id + '&j_id=' + j_id + '&ifzj=1' + '&key_words=' + key_words,
      // })
      wx.navigateTo({
        url: '/hyb_yl/backstageServices/pages/yaotang/yaotang?inquiry=' + this.data.inquiry + '&zhenduan=' + zhenduan + '&yongyao=' + yongyao + '&text=' + text + '&c_id=' + c_id + '&j_id=' + j_id + '&ifzj=1' + '&key_words=' + key_words + '&back_orser=' + back_orser+'&zid='+zid,
      })
    }

  },
  // 常见疾病
  chooseLabel(e) {
    let i = e.currentTarget.dataset.dex,
      arrs = this.data.speedlist
    console.log(i)
    console.log(arrs)
    this.setData({
      textareatxt: arrs[i].text
    })
  },
  //关闭模态框
  closepop() {
    this.setData({
      popif: false
    })
  },
  nopingzheng() {
    this.setData({
      popif: true
    })
  },
  //开方
  navUrgent() {
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/chufangmes/chufangmes?inquiry=3',
    })
  },
  //删除图片
  deleteimg: function (e) {
    var that = this;
    var i = e.currentTarget.dataset.index;
    var imgArr = that.data.data_arr;
    imgArr.splice(i, 1);
    that.setData({
      upload_picture_list: imgArr
    })
  },
  // 上传图片
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res)
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr
              })
            }
          })
        }
      }
    })
  },
  // 是否同意协议
  radioChange() {
    this.setData({
      argeen: !this.data.argeen
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var id = options.id
    var bgc = wx.getStorageSync('color')
    var j_id = options.j_id
    var c_id = options.c_id
    var ifzj = options.ifzj
    var text = options.text
    var key_words = options.key_words
    var zid = options.zid
    if (options.back_orser) {
      var back_orser = options.back_orser
    } else {
      var back_orser = 0
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        that.setData({
          url: res.data,
        })
      }
    })
    this.setData({
      id: id,
      j_id: j_id,
      c_id: c_id,
      ifzj: ifzj,
      text: text,
      key_words: key_words,
      back_orser: back_orser,
      zid:zid
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // this.getcfdetail()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  // getcfdetail() {
  //   var that = this
  //   var id = that.data.id
  //   app.util.request({
  //     'url': 'entry/wxapp/zhuanjia.getcfdetail',
  //     data: {
  //       c_id: id
  //     },
  //     success: function (res) {
  //       console.log(res)
  //       that.setData({
  //         detail: res.data
  //       })
  //     }
  //   })
  // }
})